package com.eco.mam.work.request;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;

import org.apache.log4j.Logger;

import com.eco.mam.work.DataException;
import com.eco.mam.work.request.dto.Address;
import com.eco.mam.work.request.dto.MeterPoiint;
import com.eco.mam.work.request.dto.Transaction;
import com.eco.mam.work.request.dto.WorkRequest;

public class WorkRequestProcessHelper {
	static final Logger logger = Logger
			.getLogger(WorkRequestProcessHelper.class);
	//This method populate WorkRequest object from csv values.
    public WorkRequest createWorkRequestObjectFromCsvStringTokens(
            String[] strCsvValues) {
        Transaction transaction = new Transaction();
        WorkRequest workRequest = new WorkRequest();
        MeterPoiint meterPoint = new MeterPoiint();
        Address address = new Address();
        for (int i = 0; i < strCsvValues.length; i++) {
            switch (i) {
            case 0:
                transaction.setTransctionRecordIdentifier(strCsvValues[0]);
                break;
            case 1:
                transaction.setTransactionReference(strCsvValues[1]);
                break;
            case 2:
                transaction.setContractReference(strCsvValues[2]);
            case 3:
                transaction.setTransactionTypeCode(strCsvValues[3]);
                break;
            case 4:
                transaction.setTransactionTypeCode(strCsvValues[4]);
                break;
            case 5:
                meterPoint.setmTPT_RecordIdentifier(strCsvValues[5]);
                break;
            case 6:
                meterPoint.setStmeterPointRefereneNumber(strCsvValues[6]);
                break;
            case 7:
                meterPoint.setLocationCode(strCsvValues[7]);
                break;
            case 8:
                address.setAddressTypeCode(strCsvValues[8]);
                break;
            case 9:
                address.setPostCode(strCsvValues[9]);
                break;
            case 10:
                address.setPostTown(strCsvValues[10]);
                break;
            case 11:
                address.setCounty(strCsvValues[11]);
                break;

            default:
                break;
            }

        }
        meterPoint.setAddress(address);
        transaction.setMeterPoint(meterPoint);
        workRequest.setTransaction(transaction);
if(logger.isDebugEnabled()){
        logger.debug("before returning  from :createWorkRequestObjectFromCsvStringTokens()  :"+workRequest);
}
        return workRequest;
    }
    

}
